# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=libfido2
pkgver=1.14.0
pkgrel=0
pkgdesc="library for FIDO 2.0 functionality"
url="https://github.com/Yubico/libfido2"
arch="all"
license="BSD-2-Clause"
install="$pkgname.pre-install"
makedepends="cmake libcbor-dev openssl-dev>3 zlib-dev eudev-dev linux-headers samurai"
subpackages="$pkgname-dev $pkgname-doc fido2:fido"
source="$pkgname-$pkgver.tar.gz::https://github.com/Yubico/libfido2/archive/refs/tags/$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest -j4
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm644 -t "$pkgdir"/lib/udev/rules.d/ "$builddir"/udev/70-u2f.rules
}

fido() {
	pkgdesc="commandline utilities for FIDO 2.0"
	amove usr/bin
}

sha512sums="
83454b0db0cc8546f377d0dd59f95785fe6b73cf28e499a6182a6ece4b7bce17c3e750155262adf71f339ec0b3b6c3d3d64a07b01c8428b4b91de97ae768f0e6  libfido2-1.14.0.tar.gz
"
